package main

import (
	"fmt"
	"runtime"
	"tools_go/basic_learn/concurent"
)

func main() {
	// concurent.Go_f1()
	// concurent.Go_f2()
	//concurent.Go_f3()
	// concurent.Go_wg_1()
	// 子协程
	/* go showMsg("golang")
	for i := 0; i < 6; i++ {
		// 切一下时间片  CPU再次分配任务  当然有可能会再次分配给自己  类似与java的yeild
		runtime.Gosched()
		fmt.Printf("i: %v, msg: gojava \n", i)
	} */

	/* go show()
	time.Sleep(time.Second) */
	//concurent.GoMaxProcs()
	//concurent.MutexTest()
	// concurent.IterChan_f1()
	// concurent.SelectChan()
	// concurent.Timer_f1()
	// concurent.Timer_f2()
	// concurent.Timer_f3()
	// concurent.Timer_f4()
	// concurent.Ticker_f1()
	// concurent.Ticker_f2()
	// concurent.Atomic_f1()
	concurent.Atomic_f2()
}

func show() {
	for i := 0; i < 10; i++ {
		if i >= 5 {
			runtime.Goexit()
		}
		fmt.Printf("i: %v\n", i)
	}
}

func showMsg(msg string) {
	for i := 0; i < 6; i++ {
		fmt.Printf("i: %v, msg: %v \n", i, msg)
	}
}
